/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     sliderBar.c
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-04
  * @brief    This file contains the functions prototypes for the UartTFT
  *           Application display firmware.
 ********************************************************************************/
#include "sliderBar.h"
#include "bsp.h"
#include "data.h"
#include "popupBox.h"
#include "levetop.h"
#include "transport.h"
#include "uart.h"
#include "function_drv.h"

/*sliding progress bar*/
uint8_t Slide_count = 0;
uint8_t Slide_flag = 0;
uint8_t slide_first_touch = 0;
uint8_t slide_num = 0;
Slide_Info gSlide_Info[SLIDE_SIZE];


/***********************************************************************************
 * Function Name : Disp_slide
 * Description   : Display sliding progress bar.
 * Input         : - i: which number of sliding progress bar
 * Output        : None
 * Return        : None
 ************************************************************************************/
void Disp_slide(uint8_t i)
{
    uint8_t buff[12] = {0};
    int16_t sum = 0;
    uint16_t w, h;
    uint16_t bgw, bgh;

    // progress bar is empty
    if (gSlide_Info[i].slideid == 0xFFFF) return;

    // touch icon
    if (gSlide_Info[i].arrowid != 0xFFFF)
    {
        LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].arrowid + multi_language * 12 * addr_index[11], 12);
        PICINFO[2].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
        PICINFO[2].w = buff[4] + (buff[5] << 8);
        PICINFO[2].h = buff[6] + (buff[7] << 8);
        PICINFO[2].flag = buff[11];
    }
    else
    {
        PICINFO[2].w = 0;
        PICINFO[2].h = 0;
        PICINFO[2].w = 0;
        PICINFO[2].h = 0;
    }

    // progress bar
    LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].slideid + multi_language * 12 * addr_index[11], 12);
    pic_add = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
    pic_w = buff[4] + (buff[5] << 8);
    pic_h = buff[6] + (buff[7] << 8);
    pic_len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
    pic_flag = buff[11];

    PICINFO[1].addr = pic_add;
    PICINFO[1].w = pic_w;
    PICINFO[1].h = pic_h;
    PICINFO[1].flag = pic_flag;
    PICINFO[1].x = gSlide_Info[i].x2;
    PICINFO[1].y = gSlide_Info[i].y2;

    // progress bar background
    if (gSlide_Info[i].bgid != 0xFFFF)
    {
        LT_ReadFlash_UI(buff, addr_index[10] + 12 * gSlide_Info[i].bgid + multi_language * 12 * addr_index[11], 12);
        PICINFO[0].addr = (buff[0]) + (buff[1] << 8) + (buff[2] << 16) + (buff[3] << 24);
        PICINFO[0].w = buff[4] + (buff[5] << 8);
        PICINFO[0].h = buff[6] + (buff[7] << 8);
        PICINFO[0].len = buff[8] + (buff[9] << 8) + (buff[10] << 16);
        PICINFO[0].flag = buff[11];

        PICINFO[0].x = gSlide_Info[i].x1;
        PICINFO[0].y = gSlide_Info[i].y1;

        // full-screen background
        if (PICINFO[0].flag == 1 || PICINFO[0].flag == 2)
        {
        	if (pic_update == 0)
				LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
									PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
        }

        // progress bar
        if (pic_update == 0)
			LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
								0, 0, PICINFO[0].w, PICINFO[0].addr,
								PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);
		else
			LT268_pic_to_buffer(PICINFO[0].x, PICINFO[0].y, FullScreen_w, m_PngData,
											0, 0, PICINFO[0].w, PICINFO[0].addr,
											PICINFO[0].w, PICINFO[0].h, PICINFO[0].flag);

        // progress bar
        PICINFO[1].x = PICINFO[1].x - PICINFO[0].x;
        PICINFO[1].y = PICINFO[1].y - PICINFO[0].y;

        // touch icon
        if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
        {
            if (PICINFO[2].h < PICINFO[1].h)
                PICINFO[2].y = PICINFO[1].y + (PICINFO[1].h - PICINFO[2].h) / 2;
            else
                PICINFO[2].y = PICINFO[1].y - (PICINFO[2].h - PICINFO[1].h) / 2;
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Xs - PICINFO[0].x < PICINFO[2].w/2)
                    gSlide_Info[i].Xs = PICINFO[0].x + PICINFO[2].w/2;
                if(PICINFO[0].x + PICINFO[0].w - gSlide_Info[i].Xe < PICINFO[2].w/2)
                    gSlide_Info[i].Xe = PICINFO[0].x + PICINFO[0].w - PICINFO[2].w/2;
            }
        }
        else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
        {
            if (PICINFO[2].w < PICINFO[1].w)
                PICINFO[2].x = PICINFO[1].x + (PICINFO[1].w - PICINFO[2].w) / 2;
            else
                PICINFO[2].x = PICINFO[1].x - (PICINFO[2].w - PICINFO[1].w) / 2;
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Ys - PICINFO[0].y < PICINFO[2].h/2)
                    gSlide_Info[i].Ys = PICINFO[0].y + PICINFO[2].h/2;
                if(PICINFO[0].y + PICINFO[0].h - gSlide_Info[i].Ye < PICINFO[2].h/2)
                    gSlide_Info[i].Ye = PICINFO[0].y + PICINFO[0].h - PICINFO[2].h/2;
            }
        }
    }
    else
    {

        // Coordinate calculation
        if (gSlide_Info[i].direction == 0 || gSlide_Info[i].direction == 1)
        {
            PICINFO[0].w = PICINFO[1].w; // max w
            PICINFO[0].x = PICINFO[1].x;
            PICINFO[1].x = 0;
            if (PICINFO[2].h < PICINFO[1].h)
            {
                PICINFO[0].h = PICINFO[1].h;
                PICINFO[0].y = PICINFO[1].y;
                PICINFO[1].y = 0;
                PICINFO[2].y = (PICINFO[1].h - PICINFO[2].h) / 2;
            }
            else
            {
                PICINFO[0].h = PICINFO[2].h;
                PICINFO[0].y = PICINFO[1].y - (PICINFO[2].h - PICINFO[1].h) / 2;
                PICINFO[1].y = (PICINFO[2].h - PICINFO[1].h) / 2;
                PICINFO[2].y = 0;
            }
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Xs - PICINFO[0].x < PICINFO[2].w/2)
                    gSlide_Info[i].Xs = PICINFO[0].x + PICINFO[2].w/2;
                if(PICINFO[0].x + PICINFO[0].w - gSlide_Info[i].Xe < PICINFO[2].w/2)
                    gSlide_Info[i].Xe = PICINFO[0].x + PICINFO[0].w - PICINFO[2].w/2;
            }
        }
        else if (gSlide_Info[i].direction == 2 || gSlide_Info[i].direction == 3)
        {
            PICINFO[0].h = PICINFO[1].h;
            PICINFO[0].y = PICINFO[1].y;
            PICINFO[1].y = 0;
            if (PICINFO[2].w < PICINFO[1].w)
            {
                PICINFO[0].w = PICINFO[1].w;
                PICINFO[0].x = gSlide_Info[i].x2;
                PICINFO[1].x = 0;
                PICINFO[2].x = (PICINFO[1].w - PICINFO[2].w) / 2;
            }
            else
            {
                PICINFO[0].w = PICINFO[2].w;
                PICINFO[0].x = gSlide_Info[i].x2 - (PICINFO[2].w - PICINFO[1].w) / 2;
                PICINFO[1].x = (PICINFO[2].w - PICINFO[1].w) / 2;
                PICINFO[2].x = 0;
            }
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                if(gSlide_Info[i].Ys - PICINFO[0].y < PICINFO[2].h/2)
                    gSlide_Info[i].Ys = PICINFO[0].y + PICINFO[2].h/2;
                if(PICINFO[0].y + PICINFO[0].h - gSlide_Info[i].Ye < PICINFO[2].h/2)
                    gSlide_Info[i].Ye = PICINFO[0].y + PICINFO[0].h - PICINFO[2].h/2;
            }
        }

        // full-screen background
//        if(PICINFO[1].flag == 1 || PICINFO[1].flag == 2)
//        LT268_pic_to_buffer(0, 0, PICINFO[0].w, m_PngData,
//                            PICINFO[0].x, PICINFO[0].y, LCD_XSIZE_TFT, FullScreen_addr,
//                            PICINFO[0].w, PICINFO[0].h, FullScreen_flag);
        if (pic_update == 0)
			LT268_BG_to_buffer(0, 0, PICINFO[0].w, m_PngData,
								PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
        else
        	LT268_BG_to_buffer(PICINFO[0].x, PICINFO[0].y,FullScreen_w, m_PngData,
        									PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);
    }

    switch (gSlide_Info[i].direction)
    {
        case 0: // From left to right
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                w = PICINFO[1].w * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//				w = gSlide_Info[i].dx - gSlide_Info[i].Xs;

            // progress bar
			if (pic_update == 0)
				LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[1].w, PICINFO[1].addr,
									w, PICINFO[1].h, PICINFO[1].flag);
			else
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[0].x, PICINFO[1].y + PICINFO[0].y, FullScreen_w, m_PngData,
									0, 0, PICINFO[1].w, PICINFO[1].addr,
									w, PICINFO[1].h, PICINFO[1].flag);

            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                w = (gSlide_Info[i].Xe - gSlide_Info[i].Xs) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                if (pic_update == 0)
					LT268_pic_to_buffer(gSlide_Info[i].Xs - PICINFO[0].x + w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
                else
                	LT268_pic_to_buffer(gSlide_Info[i].Xs + w - PICINFO[2].w / 2, PICINFO[2].y + PICINFO[0].y , FullScreen_w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 1: // From right to left
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                w = PICINFO[1].w * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}

            // progress bar
			if (pic_update == 0)
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[1].w - w, PICINFO[1].y, PICINFO[0].w, m_PngData,
									PICINFO[1].w - w, 0, PICINFO[1].w, PICINFO[1].addr,
									w, PICINFO[1].h, PICINFO[1].flag);
			else
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[1].w - w + PICINFO[0].x, PICINFO[1].y + PICINFO[0].y, FullScreen_w, m_PngData,
													PICINFO[1].w - w, 0, PICINFO[1].w, PICINFO[1].addr,
													w, PICINFO[1].h, PICINFO[1].flag);
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                w = (gSlide_Info[i].Xe - gSlide_Info[i].Xs) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
                if (pic_update == 0)
					LT268_pic_to_buffer(gSlide_Info[i].Xe - PICINFO[0].x - w - PICINFO[2].w / 2, PICINFO[2].y, PICINFO[0].w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
                else
                	LT268_pic_to_buffer(gSlide_Info[i].Xe - w - PICINFO[2].w / 2, PICINFO[2].y + PICINFO[0].y, FullScreen_w, m_PngData,
                											0, 0, PICINFO[2].w, PICINFO[2].addr,
                											PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 2: // From top to bottom

			sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
			if (sum > gSlide_Info[i].V_max)
				sum = gSlide_Info[i].V_max;
			else if (sum < gSlide_Info[i].V_min)
				sum = gSlide_Info[i].V_min;

			h = PICINFO[1].h * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

			if (pic_update == 0)
				LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y, PICINFO[0].w, m_PngData,
									0, 0, PICINFO[1].w, PICINFO[1].addr,
									PICINFO[1].w, h, PICINFO[1].flag);
			else
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[0].x, PICINFO[1].y + PICINFO[0].y, FullScreen_w, m_PngData,
													0, 0, PICINFO[1].w, PICINFO[1].addr,
													PICINFO[1].w, h, PICINFO[1].flag);

            // touch icon
            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                h = (gSlide_Info[i].Ye - gSlide_Info[i].Ys) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
                if (pic_update == 0)
					LT268_pic_to_buffer(PICINFO[2].x, gSlide_Info[i].Ys - PICINFO[0].y + h - PICINFO[2].h / 2, PICINFO[0].w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
                else
                	LT268_pic_to_buffer(PICINFO[2].x + PICINFO[0].x, gSlide_Info[i].Ys + h - PICINFO[2].h / 2, FullScreen_w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        case 3: // From bottom to top
//			if (Slide_flag == 0)
//			{
                sum = (var[gSlide_Info[i].p_add * 2] << 8) + var[gSlide_Info[i].p_add * 2 + 1];
                if (sum > gSlide_Info[i].V_max)
                    sum = gSlide_Info[i].V_max;
                else if (sum < gSlide_Info[i].V_min)
                    sum = gSlide_Info[i].V_min;

                h = PICINFO[1].h * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);
//			}
//			else
//			{
//				h = gSlide_Info[i].Ye - gSlide_Info[i].dy;
//			}

            // progress bar
			if (pic_update == 0)
				LT268_pic_to_buffer(PICINFO[1].x, PICINFO[1].y + PICINFO[1].h - h, PICINFO[0].w, m_PngData,
									0, PICINFO[1].h - h, PICINFO[1].w, PICINFO[1].addr,
									PICINFO[1].w, h, PICINFO[1].flag);
			else
				LT268_pic_to_buffer(PICINFO[1].x + PICINFO[0].x, PICINFO[1].y + PICINFO[1].h - h + PICINFO[0].y, FullScreen_w, m_PngData,
													0, PICINFO[1].h - h, PICINFO[1].w, PICINFO[1].addr,
													PICINFO[1].w, h, PICINFO[1].flag);

            if (gSlide_Info[i].arrowid != 0xFFFF)
            {
                h = (gSlide_Info[i].Ye - gSlide_Info[i].Ys) * (sum - gSlide_Info[i].V_min) / (gSlide_Info[i].V_max - gSlide_Info[i].V_min);

                if (pic_update == 0)
					LT268_pic_to_buffer(PICINFO[2].x, gSlide_Info[i].Ye - PICINFO[0].y - h - PICINFO[2].h / 2, PICINFO[0].w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
                else
                	LT268_pic_to_buffer(PICINFO[2].x + PICINFO[0].x , gSlide_Info[i].Ye - h - PICINFO[2].h / 2, FullScreen_w, m_PngData,
										0, 0, PICINFO[2].w, PICINFO[2].addr,
										PICINFO[2].w, PICINFO[2].h, PICINFO[2].flag);
            }

            break;
        default:
            break;
    }

    // display
    if (pic_update == 0)
		LT268_buffer_to_TFT(0, 0, PICINFO[0].w, m_PngData,
							PICINFO[0].x, PICINFO[0].y, PICINFO[0].w, PICINFO[0].h);

}

/***********************************************************************************
 * Function Name : Progress_bar_sliding
 * Description   : Touch detection of sliding progress bar.
 * Input         : None
 * Output        : None
 * Return        : None
 ************************************************************************************/
int VOL_flag=50;//����
int Mega_bass_flag=50;//�ص���
int Brightness_flag=50;//������
uint8_t huatiao_flag = 0;
void Progress_bar_sliding(void)
{
    uint8_t i = 0, rebuf[20];
    int32_t temp;
    int32_t sum = 0;
    int32_t step = 0;
    if (gTpInfo.sta)
    {
        for (i = 0; i < Slide_count; i++)
        {
            if (gSlide_Info[i].lastx != gTpInfo.x[0] || gSlide_Info[i].lasty != gTpInfo.y[0])
            {
                switch (gSlide_Info[i].direction)
                {
                case 0: // From left to right
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;

                        gSlide_Info[i].dx = gTpInfo.x[0];
                        if (gTpInfo.x[0] > gSlide_Info[i].Xe)
                            gSlide_Info[i].dx = gSlide_Info[i].Xe;
                        else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
                            gSlide_Info[i].dx = gSlide_Info[i].Xs;

                        step = 1000*(gSlide_Info[i].V_max - gSlide_Info[i].V_min)/(gSlide_Info[i].Xe - gSlide_Info[i].Xs);
                        if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].dx - gSlide_Info[i].Xs) * step/1000 + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lasty = gTpInfo.y[0];
                        if (gSlide_Info[i].lastx != gTpInfo.x[0])
                        {
                            gSlide_Info[i].lastx = gTpInfo.x[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 1: // From right to left
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs - 40 && gTpInfo.y[0] >= gSlide_Info[i].Ys &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe + 40 && gTpInfo.y[0] <= gSlide_Info[i].Ye &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dx = gTpInfo.x[0];
                        if (gTpInfo.x[0] > gSlide_Info[i].Xe)
                            gSlide_Info[i].dx = gSlide_Info[i].Xe;
                        else if (gTpInfo.x[0] < gSlide_Info[i].Xs)
                            gSlide_Info[i].dx = gSlide_Info[i].Xs;

                        step = 1000*(gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (gSlide_Info[i].Xe - gSlide_Info[i].Xs);
                        if (gSlide_Info[i].dx == gSlide_Info[i].Xs)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else if (gSlide_Info[i].dx == gSlide_Info[i].Xe)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].Xe - gSlide_Info[i].dx) * step/1000 + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lasty = gTpInfo.y[0];
                        if (gSlide_Info[i].lastx != gTpInfo.x[0])
                        {
                            gSlide_Info[i].lastx = gTpInfo.x[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 2: // From top to bottom
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dy = gTpInfo.y[0];
                        if (gTpInfo.y[0] > gSlide_Info[i].Ye)
                            gSlide_Info[i].dy = gSlide_Info[i].Ye;
                        else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
                            gSlide_Info[i].dy = gSlide_Info[i].Ys;

                        step = 1000*(gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (gSlide_Info[i].Ye - gSlide_Info[i].Ys);
                        if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].dy - gSlide_Info[i].Ys) * step/1000 + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }

                        gSlide_Info[i].lastx = gTpInfo.x[0];
                        if (gSlide_Info[i].lasty != gTpInfo.y[0])
                        {
                            gSlide_Info[i].lasty = gTpInfo.y[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                case 3: // From bottom to top
                    if (gTpInfo.x[0] >= gSlide_Info[i].Xs && gTpInfo.y[0] >= gSlide_Info[i].Ys - 40 &&
                            gTpInfo.x[0] <= gSlide_Info[i].Xe && gTpInfo.y[0] <= gSlide_Info[i].Ye + 40 &&
                            ((slide_first_touch == 0 && button_Press_flag == 0) || (slide_first_touch == 1 && slide_num == i)))
                    {
                        if (slide_first_touch == 0)
                        {
                            slide_first_touch = 1;
                            if (buzzer)
                                touch_buzzer();
            				if(huatiao_flag==0)
            				{
            					huatiao_flag=1;
            					//LTPrintf("down\n");
            				}
                   		    fanhui_timesum=0;
                        }
                        slide_num = i;
                        button_Press_flag = 1;
                        gSlide_Info[i].dy = gTpInfo.y[0];
                        if (gTpInfo.y[0] > gSlide_Info[i].Ye)
                            gSlide_Info[i].dy = gSlide_Info[i].Ye;
                        else if (gTpInfo.y[0] < gSlide_Info[i].Ys)
                            gSlide_Info[i].dy = gSlide_Info[i].Ys;

                        step = 1000*(gSlide_Info[i].V_max - gSlide_Info[i].V_min) / (gSlide_Info[i].Ye - gSlide_Info[i].Ys);
                        if (gSlide_Info[i].dy == gSlide_Info[i].Ys)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_max >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_max & 0xff;
                        }
                        else if (gSlide_Info[i].dy == gSlide_Info[i].Ye)
                        {
                            var[gSlide_Info[i].p_add * 2] = gSlide_Info[i].V_min >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = gSlide_Info[i].V_min & 0xff;
                        }
                        else
                        {
                            temp = (gSlide_Info[i].Ye - gSlide_Info[i].dy) * step/1000 + gSlide_Info[i].V_min;
                            var[gSlide_Info[i].p_add * 2] = temp >> 8;
                            var[gSlide_Info[i].p_add * 2 + 1] = temp & 0xff;
                        }
                        gSlide_Info[i].lastx = gTpInfo.x[0];
                        if (gSlide_Info[i].lasty != gTpInfo.y[0])
                        {
                            gSlide_Info[i].lasty = gTpInfo.y[0];
                            Slide_flag = 1;
                        }
                    }
                    break;
                default:
                    break;
                }
                if (Slide_flag == 1)
                {
                    if (gSlide_Info[i].p_add >= VAR_ADDR_S)
                        reg_operation(gSlide_Info[i].p_add);

                    page_date_update(pic_id);
                    Disp_slide(i);
                    Slide_flag = 0;
                }
            }
        }
    }
    else if (slide_first_touch == 1)
    {
    	if(huatiao_flag==1)
    	{
			if(pic_id==5)
			{
			 VOL_flag=var[0x0406*2+1];
			rebuf[3] = 0x01;
			rebuf[4] = VOL_flag;
			rebuf[5] = 0x01;
            rebuf[6] = 0X00;
            rebuf[7] = 0xBB;
            LT_SendData_CRC_Frame(rebuf, 5);
			//send_data_ALL(0x01,VOL_flag,0x01);
			 fanhui_timesum=0;
			 huatiao_flag=0;
			}
			if(pic_id==8)
			{
			 Mega_bass_flag=var[0x080A*2+1];
			rebuf[3] = 0x07;
			rebuf[4] = Mega_bass_flag;
			rebuf[5] = 0x01;
            rebuf[6] = 0X00;
            rebuf[7] = 0xBB;
            LT_SendData_CRC_Frame(rebuf, 5);
			}
			if(pic_id==9)
			{
			 Brightness_flag=var[0x090B*2+1];
			//rebuf[3] = 0x08;
			//rebuf[4] = Brightness_flag;
			//rebuf[5] = 0x01;
			//rebuf[6] = 0xBB;
			//LT_SendData_CRC_Frame(rebuf, 4);
			}
    	}
        slide_first_touch = 0;
        button_Press_flag = 0;
        if (gSlide_Info[slide_num].Code == 0xC004)
        {
            rebuf[3] = 0x41;
            rebuf[4] = gSlide_Info[slide_num].p_add >> 8;
            rebuf[5] = gSlide_Info[slide_num].p_add & 0xFF;
            rebuf[6] = var[gSlide_Info[slide_num].p_add * 2];
            rebuf[7] = var[gSlide_Info[slide_num].p_add * 2 + 1];
            Var_AddrToReg(&rebuf[4]);
            LT_InfoFeedback_with_addr(rebuf, 5);
        }
    }
}





